

import { h } from 'vue'
import Editor from '@/components/monaco-editor'
import { isFunction } from 'lodash'
import type { IJsonItem } from '../types'

export function renderEditor(
  item: IJsonItem,
  fields: { [field: string]: any }
) {
  const { props, field } = isFunction(item) ? item() : item
  return h(Editor, {
    options: props,
    value: fields[field],
    onUpdateValue: (value: string) => void (fields[field] = value)
  })
}
